#include "oci.h"
#include <stdio.h>
#include <stdlib.h>
#include "ErrorCheck.h"
#include <assert.h>

//check return status of each OCI calls.
//note:we should customize this function to meet our goals, like write error log or pop up a message box
//     add thread lock to make sure this function thread safe
void checkerr0(void *handle,ub4 htype,sword status)
{
	text errbuf[2048];
	sb4 errcode=0;

	switch(status)
	{
	case OCI_SUCCESS:
		break;

	case OCI_SUCCESS_WITH_INFO:
		(void) printf("error-oci success with info\n");
		break;

	case OCI_NEED_DATA:
		(void) printf("error-oci need data\n");
		break;

	case OCI_NO_DATA:
		(void) printf("error-oci no data\n");
		break;

	case OCI_ERROR:
		(void) printf("error-oci error\n");
		if (handle)
		{
			(void) OCIErrorGet(handle,1,(text *)NULL,&errcode,errbuf,(ub4)sizeof(errbuf),htype);
			(void) printf("error- %.*s\n",sizeof(errbuf),errbuf);
		}
		else
		{
			(void) printf("NULL handle\n");
			(void) printf("unable to extract detailed diagnostic information\n");
		}

		(void) printf("program will be close,please press any key\n");
		getchar();
		exit(1);
		break;

	case OCI_INVALID_HANDLE:
		(void) printf("error-oci invalid handle\n");
		break;

	case OCI_STILL_EXECUTING:
		(void) printf("error-oci still executing\n");
		break;

	case OCI_CONTINUE:
		(void) printf("error-oci continue\n");
		break;

	default:
		(void) printf("error-oci default?\n");
		break;
	}
}